<?php

$fp = fopen('Book1.csv', 'r');

$array = array();

while (!feof($fp)) {
    $str = fgets($fp);
    list($index, $type_str, $desc) = explode(';', $str);
    list($type_literal, $tipe_size) = explode(' ', $type_str);

    $type_max = 0;
    $len_id = 0;
    $type_var = 'false';
    
    if (strpos($tipe_size, '.') !== false) {
        $type_max = str_replace('.', '', $tipe_size);
        $type_var = 'true';
        $tipe_size = 0;
        
        if (strpos($tipe_size, '...') !== false) {
            $len_id = 3;
        } else if (strpos($tipe_size, '..') !== false) {
            $len_id = 2;
        } else if (strpos($tipe_size, '.') !== false) {
            $len_id = 1;
        }
    }

    $item = array();
    $item['index'] = $index;
    $item['desc'] = $desc;
    $item['type'] = 'TYPE_' . strtoupper($type_literal);
    $item['len'] = $tipe_size;
    $item['var'] = $type_var;
    $item['max'] = $type_max;
    $item['lid'] = $len_id;

    $array[] = $item;
}

//A.Add(New Field(0, FieldTypes.TYPE_N, 1, 2, 3, 4, ""))
foreach ($array as $item) {
    echo "A.Add(New Field({$item['index']}, FieldTypes.{$item['type']}, {$item['len']}, {$item['var']}, {$item['max']}, {$item['lid']}, \"{$item['desc']}\")) <br/>\r\n";
}

echo '<table border=1>';
foreach ($array as $item) {
    echo '<tr>';
    foreach ($item as $field) {
        echo '<td>';
        echo $field;
        echo '</td>';
    }
    echo '</tr>';
}
echo '</table>';
